from __future__ import absolute_import, unicode_literals
from celery import Celery
from datetime import timedelta
import os

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'blog.settings')

broker = f'redis://:{os.environ.get("CELERY_REDIS_PASSWORD")}@120.78.12.187:6379/1'
backend = f'redis://:{os.environ.get("CELERY_REDIS_PASSWORD")}@120.78.12.187:6379/2'

app = Celery('celery',
             broker= broker,
             backend= backend,
             )
# app = Celery()
#
# app.config_from_object('celery_config')
#
# # 自动注册任务
# app.autodiscover_tasks()


# 配置定时任务
app.conf.timezone= 'Asia/Shanghai'
app.conf.enable_utc = False

app.conf.beat_schedule = {
    'add-task': {
        'task': 'home.views.crontab_redis',
        'schedule': timedelta(seconds=300),
        }
}